home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 247 / 247.d81 / e.ml sub < prev    next >
Text File  |  2022-08-26  |  2KB  |  83 lines

  1. u                            PRINT THIS
  2.  
  3.             ML SUBTRACTION
  4.             --------------
  5.  
  6.    LN = Large Number
  7.    SN = Smaller Number
  8.  
  9.  
  10.        LDA LN
  11.        LDY LN+1
  12.        SEC
  13.        SBC SN
  14.        TAX
  15.        TYA
  16.        SBC SN+1
  17.        RTS
  18.  
  19.        HIGH BYTE > .A
  20.        LOW BYTE  > .X
  21.        CARRY SET if POSITIVE VALUE
  22.  
  23.  NOTE: If value to be subtracted
  24.        is already in .A register,
  25.        it can be subtracted from
  26.        another value this way:
  27.  
  28.        (.A < SN)
  29.  
  30.        EOR#255
  31.        SEC
  32.        ADC LN
  33.  
  34.  
  35.     The addition feature of the 6502
  36. processor is the most complicated
  37. function of the chip -- and a genuine
  38. work of art. Even more clever is how
  39. the designers made a "subtract"
  40. feature without having to create extra
  41. logic code.
  42.  
  43.     Subtraction is, in fact, adding a
  44. negative value to a value. In binary
  45. math, one makes a negative value our
  46. of a positive value by
  47.  
  48.         Flipping the Bits
  49.         Adding 1
  50.  
  51.     Now watch carefully. By having
  52. only ADC and SBC instructions (which
  53. require the programmer to Clear or Set
  54. the Carry), not only are multi-byte
  55. operations possible, but the
  56. programmer provides the "Adding 1"
  57. part of making a negative value for
  58. subtraction.
  59.  
  60.     When a value is to be subtracted
  61. from the contents of .A, the SBC
  62. instruction evidently does the
  63. Flipping of the Bits as the byte
  64. enters the processor.
  65.  
  66.            .A < %00001111
  67.  
  68.  SBC #%00001100
  69.  
  70.        becomes: %11110011
  71.  
  72.            SEC         +1
  73.                 ---------
  74.        and ADC
  75.  
  76.                  00000011 w/CARRY=1
  77.  
  78.     What efficiency! What Style! What
  79. Poetry!
  80.  
  81.  DMM
  82.  
  83.  
  84.